/**
 * 
 */
package edu.unc.comp410.colemangeer.model;

import org.apache.log4j.Logger;

import edu.unc.comp410.colemangeer.model.constraints.IConstraint;
import edu.unc.comp410.colemangeer.model.object.MutableObject;

/**
 * Represents a positive quantity of a CatalogItem
 * 
 * 
 * @author ccoleman
 */
public class LineItem extends MutableObject implements IConstraint {

private static Logger log = Logger.getLogger(LineItem.class);
	
	private Integer quantity;
	public Integer getQuantity() {
		return quantity;
	}

	// quantity must be >= 1
	public void setQuantity(Integer quantity) {
		if (quantity < 1)
			throw new IllegalArgumentException();
		this.quantity = quantity;
	}

	public CatalogItem getCatalogItem() {
		return item;
	}

	// item cannot be null
	public void setItem(CatalogItem item) {
		if (item==null)
			throw new IllegalArgumentException();
		this.item = item;
	}

	private CatalogItem item;
	
	// bar use of empty constructor
	private LineItem(){
	}

	public LineItem(CatalogItem item, Integer quantity){
		setItem(item);
		setQuantity(quantity);
	}
	
	public LineItem (CatalogItem item){
		setItem(item);
		setQuantity(1);
	}
	
	//TODO: sort out price methods for this class
	
	// get the base unit price * quantity
	public double getBaseSalePrice(){
		return quantity * item.getSalePrice();
	}
	
	// tax is computed by passing a shipping location to the catalog item
	
	public double getSalePriceWithTax(ShippingInfo taxLocation){
		return quantity * item.getTaxedSalePrice(taxLocation);
	}

	//TODO: add getUnitBasePrice, getUnitPriceWithTax
	
	/**
	 * Inherited methods
	 */
	
	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.object.MutableObject#clone()
	 */
	@Override
	public Object clone() throws CloneNotSupportedException {
		return new LineItem (this.getCatalogItem(), this.getQuantity());
	}

	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.object.MutableObject#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (! (obj instanceof LineItem))
			return false;
		LineItem compareItem = (LineItem) obj;
		
		return this.getQuantity().equals(compareItem.getQuantity()) &&
			this.getCatalogItem().equals(compareItem.getCatalogItem());
		
	}

	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.object.MutableObject#hashCode()
	 */
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.object.MutableObject#toString()
	 */
	@Override
	public String toString() {
		return getQuantity() + " | " + getCatalogItem().toString();
	}

	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.constraints.IConstraint#getConstraintName()
	 */
	@Override
	public String getConstraintName() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.constraints.IConstraint#isLegal(java.lang.Object)
	 */
	@Override
	public boolean isLegal(Object theObject) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see edu.unc.comp410.colemangeer.model.constraints.IConstraint#validate(java.lang.Object)
	 */
	@Override
	public void validate(Object theObject) throws IllegalStateException {
		// TODO Auto-generated method stub

	}

}
